package com.mlm.mlmapp.adapter.view;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.androidquery.AQuery;
import com.flyco.dialog.widget.base.BaseDialog;
import com.mlm.mlmapp.R;
import com.mlm.mlmapp.adapter.view.adapter.DialogItemsAdapter;
import com.mlm.mlmapp.adapter.view.listener.DialogListener;
import com.mlm.mlmapp.cons.HTTPCons;

public class OrderDialog extends BaseDialog implements HTTPCons {
	private Context mContext;
	private int layout;
	MyListView items;
	List<JSONObject> list = new ArrayList<JSONObject>();
	DialogItemsAdapter adapter;
	AQuery aq;
	TextView apply;
	TextView cancel;
	TextView sub_title;
	TextView tv_title;
	EditText tv_reason;
	HashMap<String, String> map = new HashMap<>();
	DialogListener l;
	String subtitle;
	String title;
	public OrderDialog(Context context, DialogListener l, String subtitle,String title) {
		super(context);
		// TODO Auto-generated constructor stub
		this.mContext = context;
		this.l = l;
		this.subtitle = subtitle;
		this.title = title;
		aq = new AQuery(context);
	}

	@Override
	public View onCreateView() {
		// TODO Auto-generated method stub
		View inflate = View.inflate(context, R.layout.order_dialog, null);
		tv_title=(TextView) inflate.findViewById(R.id.title);
		sub_title=(TextView) inflate.findViewById(R.id.sub_title);
		tv_reason=(EditText) inflate.findViewById(R.id.tv_reason);
		tv_title.setText(title);
		if(subtitle!=null){
			sub_title.setVisibility(View.VISIBLE);
			sub_title.setText(subtitle);
		}else {
			sub_title.setVisibility(View.GONE);
			tv_reason.setVisibility(View.VISIBLE);
		}
		
		apply = (TextView) inflate.findViewById(R.id.apply);
		cancel = (TextView) inflate.findViewById(R.id.cancel);
		apply.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(tv_reason.getText().toString().length()==0&&tv_reason.getVisibility()==View.VISIBLE){
					Toast.makeText(aq.getContext(),
							"请输入退款原因",
							Toast.LENGTH_LONG).show();

					return;
				}


				JSONObject obj=new JSONObject();
				try {
					obj.put("reason", tv_reason.getText().toString());
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				l.onApply(obj,null);
			}
		});
		cancel.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				OrderDialog.this.dismiss();
			}
		});
		return inflate;
	}

	public void setLayout(int layout) {
		this.layout = layout;
	}
	@Override
	public boolean setUiBeforShow() {
		// TODO Auto-generated method stub
		return false;
	}

}
